$(function (){
    $("#update").hide();
    $("#tableinfo").bootstrapTable({
        method:'post',
        //请求头部设置
        contentType:'application/json',
        url:'/TYMDfile/selall',
        //设置交替样式
        striped: true,
        //初始显示页号
        pageNumber:1,
        //设置表格高度
        //height:350,
        //是否显示分页
        pagination:true,
        //设置是服务端分页还是客户端分页
        sidePagination:'server',
        //每页显示条数
        pageSize:5,
        //可选每页显示数量
        pageList:[2,3,4,5],
        //上传到服务段的参数
        queryParams:function (params) {
            return{
                //计算页号（当前页）
                pageNum: (params.offset / params.limit) + 1,
                pageSize:params.limit,
                productName:$("#mingzi").val(),
                type:$("#leix").val(),
                kairegisterTime:$("#kairegisterTime").val(),
                moregisterTime:$("#moregisterTime").val()
            };
        },
        columns:[
            {title:"产品编号" , field:"productId" , align:'center'},
            {title:"产品名称" , field:"productName" , align:'center'},
            {title:"用途类型" , field:"type" , align:'center',
                formatter:function (value,row,index) {
                    if(value==""){
                        return "";
                    }else {
                        if(value==1){
                            return "商品";
                        }else {
                            return "物料";
                        }
                    }
                }},
            {title:"I级分类" , field:"firstKindName" , align:'center'},
            {title:"II级分类" , field:"secondKindName" , align:'center'},
            {title:"III级分类" , field:"thirdKindName" , align:'center'},
            {title:"产品经理" , field:"responsiblePers" , align:'center',
                formatter:function (value,row,index) {
                    if(value==null){return "";}else {return value;}
                }
            },
            {title: "操作",field:"fileId",align: 'center',
                formatter:function (value,row,index) {
                    var btn1 = "<button type='button' class='btn btn-info' onclick='shows("+value+")'>查看</button>";
                    return btn1;
                }
            }]
    })
})

function sel() {
    $("#tableinfo").bootstrapTable("refresh");
}

function shows(a) {
    $("#table").hide();
    $("#update").show();
    $("#checked").html(parent.document.getElementsByClassName("user_name")[0].innerHTML);
    $.ajax({
        url:"/TYMDfile/"+a,
        type:"post",
        contentType:"application/json;charset=utf-8",
        dataType:"json",
        success:function (data) {
            $("#productId").html(data.productId);
            $("#productName").html(data.productName);
            $("#firstKindId").val(data.firstKindId);
            $("#thirdKindId").val(data.thirdKindId);
            $("#type").val(data.type);
            $("#personalUnit").html(data.personalUnit);
            $("#listPrice").html(data.listPrice);
            $("#factoryName").html(data.factoryName);
            $("#secondKindId").val(data.secondKindId);
            $("#productNick").html(data.productNick);
            $("#productClass").val(data.productClass);
            $("#personalValuue").html(data.personalValuue);
            $("#costPrice").html(data.costPrice);
            $("#warranty").html(data.warranty);
            $("#twinId").html(data.twinId);
            $("#amoutUnil").html(data.amoutUnil);
            $("#providerGroup").val(data.providerGroup);
            $("#register").html(data.register);
            $("#twinName").html(data.twinName);
            $("#lifecycle").html(data.lifecycle);
            $("#responsiblePers").val(data.responsiblePers);
            $("#productDescribe").val(data.productDescribe);
            $("#deptId").val(data.deptId);
        }
    })
}

function fan() {
    $("#table").show();
    $("#update").hide();
}

function shows(a) {
    $("#table").hide();
    $("#update").show();
    $("#checked").html(parent.document.getElementsByClassName("user_name")[0].innerHTML);
    $.ajax({
        url:"/TYMDfile/"+a,
        type:"post",
        contentType:"application/json;charset=utf-8",
        dataType:"json",
        success:function (data) {
            $("#productId").html(data.productId);
            $("#productName").html(data.productName);
            $("#firstKindId").val(data.firstKindId);
            $("#thirdKindId").val(data.thirdKindId);
            $("#type").val(data.type);
            $("#personalUnit").html(data.personalUnit);
            $("#listPrice").html(data.listPrice);
            $("#factoryName").html(data.factoryName);
            $("#secondKindId").val(data.secondKindId);
            $("#productNick").html(data.productNick);
            $("#productClass").val(data.productClass);
            $("#personalValuue").html(data.personalValuue);
            $("#costPrice").html(data.costPrice);
            $("#warranty").html(data.warranty);
            $("#twinId").html(data.twinId);
            $("#amoutUnil").html(data.amoutUnil);
            $("#providerGroup").val(data.providerGroup);
            $("#register").html(data.register);
            $("#twinName").html(data.twinName);
            $("#lifecycle").html(data.lifecycle);
            $("#responsiblePers").val(data.responsiblePers);
            $("#productDescribe").val(data.productDescribe);
            $("#deptId").val(data.deptId);
        }
    })
}

function fan() {
    $("#table").show();
    $("#update").hide();
}